package LEKIEUANH.ARRAYS.EX05;

public class Controllers {
	//Bubble sort
	/*public int[] SapXepMang(int[] myArr){
		for(int i = 0; i<myArr.length-1;i++){
			for(int j=i+1;j<=myArr.length-1;j++){
				if(myArr[i]>myArr[j]){
					int temp = myArr[i];
					myArr[i]=myArr[j];
					myArr[j]=temp;
				}
			}
		}
		return myArr;
	}*/
	//Selection sort
	public int[]  selectionSort(int[] myArr) {
	       for (int i = myArr.length - 1; i >= 1; i--){
	         // Find the maximum in the list[0..i]
	         int currentMax = myArr[0];
	         int currentMaxIndex = 0;
	         {for (int j = 1; j <= i; j++) {
	          if (currentMax < myArr[j]) {
	             currentMax = myArr[j];
	            currentMaxIndex = j;
	           }
	         } 
	         // Swap list[i] with list[currentMaxIndex] if necessary;
	         if (currentMaxIndex != i) {
	        	 myArr[currentMaxIndex] = myArr[i];
	        	 myArr[i] = currentMax;
	         }
	       }
	    }return myArr;
}
}
